package ynu.edu.merchant.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ynu.edu.common.result.Result;
import ynu.edu.merchant.service.MerchantService;
import ynu.edu.merchant.vo.MerchantVO;

/**
 * 内部商家控制器，提供给其他微服务调用的API
 * 这些API不需要JWT认证
 */
@RestController
@RequestMapping("/internal")
@RequiredArgsConstructor
public class InternalMerchantController {

    private final MerchantService merchantService;

    /**
     * 根据商家ID获取商家信息（内部API）
     */
    @GetMapping("/merchants/{id}")
    public Result<MerchantVO> getMerchantById(@PathVariable Long id) {
        MerchantVO merchantVO = merchantService.getMerchantById(id);
        return Result.success(merchantVO);
    }

    /**
     * 根据商家ID获取商家名称（内部API）
     */
    @GetMapping("/merchants/{id}/name")
    public Result<String> getMerchantNameById(@PathVariable Long id) {
        MerchantVO merchantVO = merchantService.getMerchantById(id);
        return merchantVO != null ? 
               Result.success(merchantVO.getName()) : 
               Result.failed("商家不存在");
    }
} 